//
//  SSSSShopDetail.m
//  Ghac 4S
//
//  Created by apple apple on 12-1-12.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//
#import "Global.h"
#import "SSSSShopDetail.h"

@interface SSSSShopDetail(private)
-(IBAction)phoneCallLabelClick:(id)sender;
@end



@implementation SSSSShopDetail
@synthesize shopNameLabel;
@synthesize addressTextView;
@synthesize phoneLabel;
@synthesize phone_24_Label;
@synthesize phone_af_sale_Label;
@synthesize showDetailData;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) 
    {
        // Custom initialization
    }
    return self;
}
-(void)setUpWithData:(id)data
{
    self.showDetailData = data;
    [self.shopNameLabel setText:[data valueForKeyPath:@"title"]];
    [self.addressTextView setText:[data valueForKeyPath:@"subtitle"]];
    
    [self.phoneLabel setTitle:[[data valueForKeyPath:@"phone"] description] forState:UIControlStateNormal];
    [self.phone_af_sale_Label setTitle:[[data valueForKeyPath:@"fax"] description] forState:UIControlStateNormal];
    [self.phone_24_Label setTitle:[[data valueForKeyPath:@"emergencyNum"] description] forState:UIControlStateNormal];
}
-(void)dealloc
{
    [self viewDidUnload];
    self.showDetailData = nil;
    [super dealloc];
}
- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle
-(void)phoneCallLabelClick:(id)sender
{
    
    NSString* phoneNum = [sender titleLabel].text;
    if([phoneNum isEqualToString:@""])
    {
        return;
    }

    UIActionSheet* myActionSheet = [[UIActionSheet alloc] initWithTitle:@"拨打电话" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:phoneNum, nil];
    [myActionSheet showInView:((UIViewController*)[Global mainRootController]).view];
    [myActionSheet release];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setUpWithData:self.showDetailData];
    // Do any additional setup after loading the view from its nib.
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSString* phoneNum = [actionSheet buttonTitleAtIndex:buttonIndex];
    [Global phoneCall:phoneNum];
}
-(void)actionSheetCancel:(UIActionSheet *)actionSheet
{
    
}
- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    self.shopNameLabel = nil;
    self.addressTextView = nil;
    self.phoneLabel = nil;
    self.phone_af_sale_Label = nil;
    self.phone_24_Label = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
